package com.svms.service.dml.impl;

import org.springframework.beans.factory.annotation.Autowired;

import com.svms.domain.dao.SvmsNumberGeneratorMapper;
import com.svms.model.SvmsNumberGenerator;
import com.svms.model.SvmsNumberGeneratorExample;
import com.svms.service.dml.iface.NumberGeneratorDMLIF;

public class NumberGeneratorDML implements NumberGeneratorDMLIF

{

	// TODO All the below methods must be refractored into only 2 methods which
	// accepts arguments and act accordingly

	private SvmsNumberGeneratorExample svmsNumberGeneratorExample = new SvmsNumberGeneratorExample();

	@Autowired
	private SvmsNumberGeneratorMapper svmsNumberGeneratorMapper;

	@Override
	public int generateVehicleId() {

		SvmsNumberGenerator numberGenerateorResult = svmsNumberGeneratorMapper
				.selectByPrimaryKey("SVMS_VEHICLE");

		// TODO - Type safe and null check needs to be done
		return numberGenerateorResult.getNextnumber();
	}

	@Override
	public int generateMovemenrId() {
		SvmsNumberGenerator numberGenerateorResult = svmsNumberGeneratorMapper
				.selectByPrimaryKey("SVMS_MOVEMENT");
		// TODO - Type safe and null check needs to be done
		return numberGenerateorResult.getNextnumber();
	}

	@Override
	public int generateTransportId() {
		SvmsNumberGenerator numberGenerateorResult = svmsNumberGeneratorMapper
				.selectByPrimaryKey("SVMS_TRANSPORT");
		// TODO - Type safe and null check needs to be done
		return numberGenerateorResult.getNextnumber();
	}

	@Override
	public int generateIndentId() {
		SvmsNumberGenerator numberGenerateorResult = svmsNumberGeneratorMapper
				.selectByPrimaryKey("SVMS_INDENT");
		// TODO - Type safe and null check needs to be done
		return numberGenerateorResult.getNextnumber();
	}

	@Override
	public int generateSpareCodeId() {
		SvmsNumberGenerator numberGenerateorResult = svmsNumberGeneratorMapper
				.selectByPrimaryKey("SVMS_SPARE_CODE");
		// TODO - Type safe and null check needs to be done
		return numberGenerateorResult.getNextnumber();
	}

	@Override
	public int generateVechielSpareId() {
		SvmsNumberGenerator numberGenerateorResult = svmsNumberGeneratorMapper
				.selectByPrimaryKey("SVMS_VEHICLE_SPARE_ID");
		// TODO - Type safe and null check needs to be done
		return numberGenerateorResult.getNextnumber();
	}

	@Override
	public void updateNextVehicleId(int nextNumber) {
		SvmsNumberGenerator numberGenerator = new SvmsNumberGenerator();
		numberGenerator.setServiceName("SVMS_VEHICLE");
		numberGenerator.setNextnumber(nextNumber);
		svmsNumberGeneratorMapper.updateByPrimaryKey(numberGenerator);
		// TODO - Type safe and null check needs to be done

	}

	@Override
	public void updateNextMovementId(int nextNumber) {
		SvmsNumberGenerator numberGenerator = new SvmsNumberGenerator();
		numberGenerator.setServiceName("SVMS_MOVEMENT");
		numberGenerator.setNextnumber(nextNumber);
		svmsNumberGeneratorMapper.updateByPrimaryKey(numberGenerator);
		// TODO - Type safe and null check needs to be done

	}

	@Override
	public void updateNextTransportId(int nextNumber) {
		SvmsNumberGenerator numberGenerator = new SvmsNumberGenerator();
		numberGenerator.setServiceName("SVMS_TRANSPORT");
		numberGenerator.setNextnumber(nextNumber);
		svmsNumberGeneratorMapper.updateByPrimaryKey(numberGenerator);
		// TODO - Type safe and null check needs to be done

	}

	@Override
	public void updateNextIndentId(int nextNumber) {
		SvmsNumberGenerator numberGenerator = new SvmsNumberGenerator();
		numberGenerator.setServiceName("SVMS_INDENT");
		numberGenerator.setNextnumber(nextNumber);
		svmsNumberGeneratorMapper.updateByPrimaryKey(numberGenerator);
		// TODO - Type safe and null check needs to be done

	}

	@Override
	public void updateNextSpareCodeId(int nextNumber) {
		SvmsNumberGenerator numberGenerator = new SvmsNumberGenerator();
		numberGenerator.setServiceName("SVMS_SPARE_CODE");
		numberGenerator.setNextnumber(nextNumber);
		svmsNumberGeneratorMapper.updateByPrimaryKey(numberGenerator);
		// TODO - Type safe and null check needs to be done

	}
	
	@Override
	public void updateNextVechielSpareId(int nextNumber) {
		SvmsNumberGenerator numberGenerator = new SvmsNumberGenerator();
		numberGenerator.setServiceName("SVMS_VEHICLE_SPARE_ID");
		numberGenerator.setNextnumber(nextNumber);
		svmsNumberGeneratorMapper.updateByPrimaryKey(numberGenerator);
		// TODO - Type safe and null check needs to be done

	}

}
